{% extends "templates/atnet_base.html" %}

{% block csslink %}
{{ super() }}
<script src="/media/js/jquery.js"></script>

{% include 'templates/includes_datatable.html' %}
{% include 'templates/includes_jquery_ui.html' %}
<script src="/media/js/form_popup.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	$('#expenditures').dataTable({
		"bPaginate": false,
		"bLengthChange": false,
		"bFilter": true,
		"bSort": false,
		"bInfo": false,
		"bAutoWidth": false,
		"oLanguage": {
			"sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
		},
		"bProcessing": true,
		"sAjaxSource": "{{ uri_for('parametrage_nature_des_depenses', imm_id=immeuble.key().id(), command='list_json') }}",
		"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
			$('td:eq(7)', nRow).html('<a href="javascript:void(0);" id="' + aData[8] + '" class="' + aData[0] + '">{{ _("Edit") }}</a>');
			if (aData[0] == 'exp_type') {
				$('td:eq(0)', nRow).html('<b>' + aData[1] + '</b>');
				$('td:eq(1)', nRow).html('<b>' + aData[2] + '</b>');
			}
				
		},
		 "aoColumnDefs": [
		                  { "bVisible": false, "aTargets": [ 0 ] },
		                  { "sClass": "aright", "aTargets": [ 1 ]}
		                  ]
	});
	
	$('#add-et').live('click', function(){
		$(this).LaunchPopup(
			{
				TableId: '#expenditures',
				DivId: '#dialog-form',
				FormId: '#generated-form',
				UrlForm: "{{ uri_for('parametrage_type_de_nature_des_depenses', imm_id=immeuble.key().id(), command='add') }}",
				Mode: 'add',
				Title: '{{ _("Add expenditure type") }}',
				UrlReturn: "{{ uri_for('parametrage_nature_des_depenses', imm_id=immeuble.key().id(), command='list') }}"
			}
		)
	});
	
	$('#add-expenditure').live('click', function(){
		$(this).LaunchPopup({
			TableId: '#expenditures',
			DivId: '#dialog-form',
			FormId: '#generated-form',
			UrlForm: "{{ uri_for('parametrage_nature_des_depenses', imm_id=immeuble.key().id(), command='add') }}",
			Mode: 'add',
			Title: '{{ _("Add expenditure") }}',
			UrlReturn: "{{ uri_for('parametrage_nature_des_depenses', imm_id=immeuble.key().id(), command='list') }}"
		})
	});
	
	$('#expenditures tbody tr a').live('click', function(e) {
		if ($(this).attr('class') == 'exp'){
			$(this).LaunchPopup({
				TableId: '#expenditures',
				DivId: '#dialog-form',
				FormId: '#generated-form',
				UrlForm: "{{ uri_for('parametrage_nature_des_depenses', imm_id=immeuble.key().id(), command='edit') }}" + e.target.id + "/",
				Mode: 'edit',
				Title: '{{ _("Edit expenditure") }}',
				UrlReturn: "{{ uri_for('parametrage_nature_des_depenses', imm_id=immeuble.key().id(), command='list') }}"
			})
		}
		else {
			$(this).LaunchPopup(
					{
						TableId: '#expenditures',
						DivId: '#dialog-form',
						FormId: '#generated-form',
						UrlForm: "{{ uri_for('parametrage_type_de_nature_des_depenses', imm_id=immeuble.key().id(), command='edit') }}" + e.target.id + "/",
						Mode: 'edit',
						Title: '{{ _("Edit expenditure type") }}',
						UrlReturn: "{{ uri_for('parametrage_nature_des_depenses', imm_id=immeuble.key().id(), command='list') }}"
					}
				)
		}
	});
});
</script>

{% endblock %}

{% block title %} 
	{{ title }}
{% endblock %}

{% block header %}
{{ header }}
{% endblock %}

{% block login%}
{% if show_login %}
{{ super() }}
{% endif %}
{% endblock%}

{% block navigation %}
{% if not show_login %}
{{ super() }}
{% endif %}
{% endblock %}

{% block page_name %}
{{ content_header }}
{% endblock %}

{% block section_menu %}
{% include 'templates/includes_parametrage_menu.html' %}
{% endblock %}

{% block main_content %}
<p>
	<p>
		<a href="javascript:void(0);" id="add-et">{{ _('Add expenditure type') }}</a>  ||  
		<a href="javascript:void(0);" id="add-expenditure">{{ _('Add expenditure') }}</a> ||
		<a href="{{ uri_for('parametrage_nature_des_depenses', imm_id=immeuble.key().id(), command='predefine') }}">{{ _('Define or restore list of expenditures') }}</a></p> 
	<div id="demo">
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="expenditures" width="100%">
		<thead>
			<tr>
				<th>{{ _(fields.type) }}</th>
				<th>{{ _(fields.code) }}</th>
				<th>{{ _(fields.title) }}</th>
				<th>{{ _(fields.reduc) }}</th>
				<th>{{ _(fields.deduc) }}</th>
				<th>{{ _(fields.subaccount) }}</th>
				<th>{{ _(fields.direction) }}</th>
				<th>{{ _(fields.TVA) }}</th>
				<th width="20"></th>
			</tr>
		</thead>
		<tbody>
		</tbody>
		<tfoot>
			<tr>
				<th>{{ _(fields.type) }}</th>
				<th>{{ _(fields.code) }}</th>
				<th>{{ _(fields.title) }}</th>
				<th>{{ _(fields.reduc) }}</th>
				<th>{{ _(fields.deduc) }}</th>
				<th>{{ _(fields.subaccount) }}</th>
				<th>{{ _(fields.direction) }}</th>
				<th>{{ _(fields.TVA) }}</th>
				<th></th>
			</tr>
		</tfoot>
	</table>
	</div>
	{% include 'templates/includes_popup_form.html' %}
</p>			
<script>
$(function() {
	var availableTagsA;
	availableTagsA = getMessages("{{ uri_for('parametrage_account', imm_id=immeuble.key().id(), command='list_names_json') }}");
	$("#subaccount").live("focus", function() {
		$(this).autocomplete({
			delay: 0,
			minLength: 0,
			source: availableTagsA
		});
		$(this).data("autocomplete").search($(this).val());
	});
});
</script>
{% endblock %}
